package com.len.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.len.base.BaseMapper;
import com.len.base.CurrentUser;
import com.len.base.impl.BaseServiceImpl;
import com.len.entity.SpOrder;
import com.len.entity.SysUser;
import com.len.mapper.SpOrderMapper;
import com.len.util.ReType;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Service
public class SpOrderService extends BaseServiceImpl<SpOrder,String> {
    @Autowired
    private SpOrderMapper spOrderMapper;

    @Override
    public BaseMapper<SpOrder, String> getMappser() {

        return spOrderMapper;
    }
    public SpOrder byNum(String byNum){
        return spOrderMapper.byNum(byNum);
    }
    public void subgmcs(String cs,String id){
        spOrderMapper.subgmcs(cs, id);
    }
   public List<SpOrder> showll(String userId){
        return spOrderMapper.showll(userId);
   };
    public List<SpOrder> show5(){
        return spOrderMapper.show5();
    };
    public List<CurrentUser> show6(){
        return spOrderMapper.show6();
    }
    public void insert1(SpOrder order){
        spOrderMapper.insert1(order);
    }
    public void update(SpOrder order){
        spOrderMapper.update(order);
    }
    public SpOrder queryById(String id){
        return spOrderMapper.queryById(id);
    }
    public SpOrder showlid(String id){
        return spOrderMapper.showlid(id);
    }
    public List<SpOrder>  showMyOrder1(String username){
        return spOrderMapper.showMyOrder1(username);
    };
    public Integer  showTB_BUYER(String username){
        return spOrderMapper.showTB_BUYER(username);
    }
    public Integer  showTB_SELLER(String username){
        return spOrderMapper.showTB_SELLER(username);
    }


    /**
     * 查询我的买单所有数据
     * @param username
     * @return
     */
    public  List<Map>  showDataTB_BUYER(String username){
        return spOrderMapper.showDataTB_BUYER(username);

    };
    /**
     * 查询我的卖单所有数据
     * @param username
     * @return
     */
    public  List<Map>  showDataTB_SELLER(String username){
        return spOrderMapper.showDataTB_SELLER(username);

    };
    /**
     * 查询我的所有数据
     * @param username
     * @return
     */
    public  List<Map>  showData(String username){
        return spOrderMapper.showData(username);

    };
    /**
     * 倒计时
     * @param username
     * @return
     */
    public   Timestamp[]  Time(String username){
        return spOrderMapper.Time(username);

    };
    /**
     * 倒计时
     * @param username
     * @return
     */
    public   Timestamp[]  Time1(String username,Timestamp timr){
        return spOrderMapper.Time1(username,timr);

    };
    public Integer userNum (String username){
        return spOrderMapper.userNum(username);
    }
    /**
     * 收货
     * @param username
     * @return
     */
    public   int  shouhuo(String username,String ID){
        return spOrderMapper.shouhuo(username,ID);

    };
    /**
     * 查询我的买单
     * @param username
     * @return
     */
    public  List<Map>  showMyOrder2(String username){
        return spOrderMapper.showMyOrder2(username);

    };
    /**
     * 查询我的买单
     * @param
     * @return
     */
    public  List<Map>  showMyOrder3(String data){
        return spOrderMapper.showMyOrder3(data);

    };
    /**
     * 委托代賣
     */
    public  List<Map>  showZfcg(String username){
        return spOrderMapper.showZfcg(username);
    };
    /**
     * 交易成功
     */
    public  List<Map>  showJycg(String username){
        return spOrderMapper.showJycg(username);
    };
    /**
     * 确认收货
     */
    public  List<Map>  showQrsh(String username){
        return spOrderMapper.showQrsh(username);
    };
    /**
     * 确认订单
     */
    public     List<Map> QrOrder (String ID){
        return spOrderMapper.QrOrder(ID);
    };
    /**
     * 收银台
     */
    public     List<Map> SytOrder (String ID){
        return spOrderMapper.SytOrder(ID);
    };

    /**
     * 个人中心
     */

    public List<Map> Selectmember (String username){
        return spOrderMapper.Selectmember(username);
    };
    /**
     * 个人中心佣金
     */

    public  Integer SelectmemberYj (String username)
    {
        return spOrderMapper.SelectmemberYj(username);
    };

    /**
     * 我的地址
     */

    public List<Map> SelectAddress (String username){
        return spOrderMapper.SelectAddress(username);
    };
    /**
     * 我的地址
     */

    public Boolean UpAddress (String name,String phone,String region,String detailedAddress,String postalCode, String username){
        return spOrderMapper.UpAddress(name,phone,region,detailedAddress,postalCode,username);
    };
    /**
     * 重新上架
     * @return
     */
    public Boolean cxsj (String tbgoodsid){
        return spOrderMapper.cxsj(tbgoodsid);
    };
    /**
     * 重新上架
     * @return
     */
    public Boolean cxsjzt (String cxsjzt){
        return spOrderMapper.cxsjzt(cxsjzt);
    };
    /**
     * jywc
     * @return
     */
    public Boolean jywc (String id){
        return spOrderMapper.jywc(id);
    };


    /**
     * yjls
     * @return
     */
    public Boolean yjls (double jy,String name,String cs){
        return spOrderMapper.yjls(jy,name,cs);
    };
    /**
     * cxyjls
     * @return
     */
    public double cxyjls (String name){
        return spOrderMapper.cxyjls(name);
    };

    /**
     * yjls1
     * @return
     */
    public List<Map> yjls1 (String username){
        System.err.println(username);
        return spOrderMapper.yjls1(username);
    };
    /**
     * tixian
     * @return
     */
    public double tixian (String username){
        return spOrderMapper.tixian(username);
    };
    /**
     * tixian
     * @return
     */
    public boolean tixian2 (double yj, String username){
        return spOrderMapper.tixian2(yj,username);
    };
    /**
     * qurenshoujuo
     * @return
     */

    public Boolean qrsh (String name, String id){
        return spOrderMapper.qrsh(name,id);
    };;
    public void checkData(String orderId){
        spOrderMapper.checkData(orderId);
    }
    public Map getPerson(String id){
        return spOrderMapper.getPerson(id);
    }
    public void insertUser(SysUser order){
        spOrderMapper.insertUser(order);
    }
    public void changePwd(String orderId,String password){
        spOrderMapper.changePwd(orderId,password);
    }
    public void updateUser(String realName, String idCard,String id){
        spOrderMapper.updateUser( realName,  idCard, id);
    }
    public void updateUserZf(CurrentUser user){
        spOrderMapper.updateUserZf(user);
    }
    public Map getZFPerson(String id){
        return spOrderMapper.getZFPerson(id);
    }
    public List<SpOrder> showall(){
        return spOrderMapper.showall();
    }

    /**
     * 分页查询所有订单
     */
    public ReType selectDataByPage(SpOrder t, int page, int limit){
        Page<Map> tPage = PageHelper.startPage(page, limit);
        List<Map> tList = spOrderMapper.selectDataByPage(t);
        for(Map map : tList){
            String state = map.get("TB_ORDER_STATE").toString();
            if(StringUtils.isNotEmpty(state)){
                if(state.equals("0")){
                    map.put("TB_ORDER_STATE","待抢购");
                }
                if(state.equals("1")){
                    map.put("TB_ORDER_STATE","待付款");
                }
                if(state.equals("2")){
                    map.put("TB_ORDER_STATE","买家已付款");
                }
                if(state.equals("3")){
                    map.put("TB_ORDER_STATE","卖家确认收款");
                }
                if(state.equals("4")){
                    map.put("TB_ORDER_STATE","交易完成");
                }
                if(state.equals("5")){
                    map.put("TB_ORDER_STATE","委托代卖");
                }
            }
        }
        return new ReType(tPage.getTotal(),tList);
    }

}
